<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Projekt na GIS'y</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" href="main.css" type="text/css" />
<link type="text/css" href="jquery-ui-1.8.12.custom.css" rel="stylesheet" />
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true&amp;key=ABQIAAAAQYJxjG6XX4gd3Po12V5buRTcziRb1D8yvioACmSx45cpNeMx1xSKMM1lzjR-RlrieVVHKRbzXh1qMw" type="text/javascript"></script>
<script type="text/javascript" src="jquery-1.5.2.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.12.custom.min.js"></script>
<script type="text/javascript" src="OLsource/OpenLayers.js"></script>
<script type="text/javascript" src="init.js"></script>
<script type="text/javascript" src="timetable.js"></script>
<script type="text/javascript" src="airport.js"></script>
<script type="text/javascript" src="airplane.js"></script>
<script type="text/javascript" src="runway.js"></script>
<script type="text/javascript" src="controls.js"></script>
<script type="text/javascript" src="engine.js"></script>


</head>
<body>
<div id="page">
    <div id="left">
        <div id="button"> <input type="button" value="Full" /> </div>
        <div id="loader">
			<div id="map"></div>
        </div>
        <div id="sliders">      
      	 <?php 
      		include "pages/sliders.html";
      	 ?>
        </div>
    </div>
    
    <div id="right">
      <div id="setRunway">      
      	<?php 
      		include "pages/runway.html";
      	?>
      </div>
        
      <div id="beingFlights">
          <?php 
          	include "pages/timeTable.html";
          ?>
      </div>
    </div>
</div>
<script type="text/javascript">
  showLoader();
  var map = init();
  var setCenterId = false;
  var simSpeed = 1;
  var airports = [];
  Airport.prototype.map = map;
  Runway.prototype.map = map;
  Airplane.prototype.map = map;
    
  var mercator = new OpenLayers.Projection("EPSG:900913");
  var geographic = new OpenLayers.Projection("EPSG:4326");
  
  // Berlin
  var berlinLocations = [];
  berlinLocations[0] = new OpenLayers.LonLat(1510674.38051, 6868251.73907); // to/from Paris
  berlinLocations[1] = new OpenLayers.LonLat(1508429.04281, 6879124.59967); // to/from London
  berlin = new Airport("Berlin", berlinLocations);
  berlin.addRunways([
    new Runway("[Berlin] P1", new OpenLayers.LonLat(1504506.86238, 6869069.73117), new OpenLayers.LonLat(1509312.84053, 6870937.66105)),
    new Runway("[Berlin] P2", new OpenLayers.LonLat(1500699.34832, 6866722.99851), new OpenLayers.LonLat(1506174.15047, 6868853.68067))
  ]);
  berlin.timetable.addFlight("toParis", "17:10");
  berlin.timetable.addFlight("toLondon", "18:59");
  berlin.timetable.addFlight("toParis", "21:10");
  berlin.timetable.addFlight("toLondon", "01:59");
  berlin.timetable.addFlight("toParis", "08:10");
  berlin.timetable.addFlight("toLondon", "12:59");  
  // Paryż
  var parisLocations = [];
  parisLocations[0] = new OpenLayers.LonLat(281375.87334, 6277928.66973); // to/from London
  parisLocations[1] = new OpenLayers.LonLat(284404.69058, 6276266.06436); // to/from Berlin
  paryz = new Airport("Paryz", parisLocations);
  paryz.addRunways([
    new Runway("[Paryz] P1", new OpenLayers.LonLat(289643.78669, 6273982.33307), new OpenLayers.LonLat(285716.83436, 6273676.58495)),
    new Runway("[Paryz] P2", new OpenLayers.LonLat(290591.31255, 6274665.66409), new OpenLayers.LonLat(284094.16515, 6274130.60490))
  ]);
  paryz.timetable.addFlight("toBerlin", "16:40");
  paryz.timetable.addFlight("toLondon", "13:59");
  paryz.timetable.addFlight("toBerlin", "20:40");
  paryz.timetable.addFlight("toLondon", "10:59");
  paryz.timetable.addFlight("toBerlin", "02:40");
  paryz.timetable.addFlight("toLondon", "06:59");
  
  
  // Londyn
  var londonLocations = [];
  londonLocations[0] = new OpenLayers.LonLat(-54297.33632, 6701198.61378); // to/from Paris
  londonLocations[1] = new OpenLayers.LonLat(-54182.58078, 6709606.68689); // to/from Berlin
  londyn = new Airport("Londyn", londonLocations);
  londyn.addRunways([
    new Runway("[Londyn] P1", new OpenLayers.LonLat(-48333.45662, 6706221.36257), new OpenLayers.LonLat(-54438.86426, 6706202.25331)),
    new Runway("[Londyn] P2", new OpenLayers.LonLat(-48383.02126, 6703950.35680), new OpenLayers.LonLat(-54201.79004, 6703912.12829))
  ]);
  londyn.timetable.addFlight("toBerlin", "10:10");
  londyn.timetable.addFlight("toParis", "22:50");
  londyn.timetable.addFlight("toBerlin", "03:50");
  londyn.timetable.addFlight("toParis", "14:50");
  londyn.timetable.addFlight("toBerlin", "18:25");
  londyn.timetable.addFlight("toParis", "20:00");
  
  airports.push(paryz, londyn, berlin);
 // berlin.connectLocations(0, paryz.locations[1]);
 // berlin.connectLocations(1, londyn.locations[1]);
 // paryz.connectLocations(0, londyn.locations[0]);
  Airport.prototype.airports = airports;
  center = new OpenLayers.LonLat(777823.19969063, 6665308.5260735);
  map.setCenter(center, 4);
  ///
  berlin.showTab();
  londyn.showTab();
  paryz.showTab();
  ///
  var date = new Date();
  var newDateString = date.getHours() + ":" + date.getMinutes();// + ":" + date.getSeconds();
  var firstCall = true;
  function simulation(dateString){
    return window.setInterval(function(){
      if(firstCall){
        newDateString = date.getHours() + ":" + date.getMinutes();// + ":" + date.getSeconds();
      }
      else{
        dateString = newDateString;
      }
      for(var i = 0; i < airports.length; i++){
          if(airports[i].timetable.checkNew(dateString, airports[i].beingFlights).toParis.length != 0){
            var airplane = new Airplane(airports[i].name, paryz.name, dateString);
            airports[i].startAirplane(airplane, paryz);
          }
          if(airports[i].timetable.checkNew(dateString, airports[i].beingFlights).toLondon.length != 0){
            var airplane = new Airplane(airports[i].name, londyn.name, dateString);
            airports[i].startAirplane(airplane, londyn);
          }
          if(airports[i].timetable.checkNew(dateString, airports[i].beingFlights).toBerlin.length != 0){
            var airplane = new Airplane(airports[i].name, berlin.name, dateString);
            airports[i].startAirplane(airplane, berlin);
          }
        if(firstCall){
          airports[i].checkBeing(dateString);
        }
      }
      date.setSeconds(date.getSeconds() + 10);
      newDateString = date.getHours() + ":" + date.getMinutes();//+ ":" + date.getSeconds();
      firstCall = false;
      hideLoader();
    }, 10000);
  }
  
  var mainClockId = simulation(newDateString);
  
</script>
</body>
</html>

